<template>
	<view class="page">
		<view class="tabs">
			<view class="tab" :class="{ active: activeTab === 0 }" @click="changeTab(0)">未使用</view>
			<view class="tab" :class="{ active: activeTab === 1 }" @click="changeTab(1)">已使用</view>
			<view class="tab" :class="{ active: activeTab === 2 }" @click="changeTab(2)">已过期</view>
		</view>

		<view class="coupon-list" v-if="coupons.length > 0">
			<!-- 优惠券列表 -->
			<view v-for="(item, index) in coupons" :key="index" class="coupon-item" :class="{ 'expired': activeTab === 2 }">
				<view class="coupon-bg">
					<image v-if="activeTab !== 2" class="bg-image" src="/static/svg/coupon-bg.svg" mode="widthFix"></image>
					<image v-else class="bg-image expired-bg" src="/static/svg/coupon-bg.svg" mode="widthFix"></image>
				</view>
				
				<view class="coupon-content">
					<view class="coupon-left">
						<view class="price">
							<text class="symbol">¥</text>
							<text class="value">{{item.price}}</text>
						</view>
					</view>
					<view class="coupon-right">
						<view class="coupon-title">{{item.title}}</view>
						<view class="coupon-date">有效期至: {{item.date}}</view>
						<view class="coupon-btn" :class="{ 'expired-btn': activeTab === 2 }">
							{{ activeTab === 2 ? '已过期' : '立即使用' }}
						</view>
					</view>
				</view>
			</view>

			<!-- 已显示全部 -->
			<view class="all-loaded">
				<view class="line"></view>
				<text class="text">已显示全部</text>
				<view class="line"></view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-state" v-else>
			<image class="empty-icon" src="/static/svg/empty-coupon.svg" mode="widthFix"></image>
			<text class="empty-text">暂无优惠券</text>
		</view>
	</view>
</template>

<script setup>
import { ref, computed } from 'vue';

// 当前选中的标签
const activeTab = ref(0);

// 切换标签方法
const changeTab = (index) => {
	activeTab.value = index;
};

// 模拟不同状态的优惠券数据
const unusedCoupons = ref([
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' },
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' },
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' },
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' }
]);

const usedCoupons = ref([
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' },
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' }
]);

const expiredCoupons = ref([
	{ price: 10, title: '女装分区无门槛优惠券', date: '2019-08-01' }
]);

// 根据当前标签计算显示的优惠券列表
const coupons = computed(() => {
	switch (activeTab.value) {
		case 0:
			return unusedCoupons.value;
		case 1:
			return usedCoupons.value;
		case 2:
			return expiredCoupons.value;
		default:
			return [];
	}
});
</script>

<style>
.page {
	background-color: #f5f5f5;
	min-height: 100vh;
	padding: 20rpx 0;
}

.tabs {
	display: flex;
	justify-content: space-around;
	background-color: #fff;
	padding: 20rpx 0;
	margin-bottom: 20rpx;
}

.tab {
	padding: 10rpx 20rpx;
	font-size: 28rpx;
	position: relative;
}

.tab.active {
	color: #ff6600;
}

.tab.active::after {
	content: '';
	position: absolute;
	bottom: -10rpx;
	left: 50%;
	transform: translateX(-50%);
	width: 40rpx;
	height: 4rpx;
	background-color: #ff6600;
}

.coupon-list {
	padding: 0 20rpx;
}

.coupon-item {
	position: relative;
	height: 200rpx;
	margin-bottom: 20rpx;
	border-radius: 10rpx;
	overflow: hidden;
}

.coupon-bg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 1;
}

.bg-image {
	width: 100%;
	height: 100%;
}

.expired-bg {
	filter: grayscale(1);
}

.coupon-content {
	position: relative;
	z-index: 2;
	display: flex;
	width: 100%;
	height: 100%;
}

.coupon-left {
	width: 35%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.coupon-left .price {
	color: #fff;
	display: flex;
	align-items: flex-start;
}

.coupon-left .symbol {
	font-size: 28rpx;
	padding-top: 10rpx;
}

.coupon-left .value {
	font-size: 80rpx;
	font-weight: bold;
	line-height: 1;
}

.coupon-right {
	flex: 1;
	padding: 20rpx 30rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}

.coupon-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
}

.coupon-date {
	font-size: 24rpx;
	color: #999;
}

.coupon-btn {
	align-self: flex-end;
	padding: 10rpx 30rpx;
	border-radius: 30rpx;
	background: linear-gradient(to right, #ff7631, #ffba22);
	color: #fff;
	font-size: 24rpx;
}

.expired-btn {
	background: #cccccc !important;
}

.all-loaded {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 40rpx 0;
}

.all-loaded .line {
	height: 1px;
	width: 100rpx;
	background-color: #ddd;
}

.all-loaded .text {
	color: #999;
	font-size: 24rpx;
	margin: 0 20rpx;
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 100rpx 0;
}

.empty-icon {
	width: 200rpx;
	margin-bottom: 20rpx;
}

.empty-text {
	font-size: 28rpx;
	color: #999;
}
</style>
